package cn.edu.sgu.www.mhxysy.enums;

import cn.edu.sgu.www.mhxysy.exception.GlobalException;
import cn.edu.sgu.www.mhxysy.restful.ResponseCode;

/**
 * 解锁状态枚举
 * @author 沐雨橙风ιε
 * @version 1.0
 */
public enum UnlockStatus {

    /**
     * 未解锁
     */
    WJS(0, "未解锁"),
    /**
     * 已解锁
     */
    YJS(1, "已解锁");

    private final Integer value;
    private final String name;

    UnlockStatus(Integer value, String name) {
        this.value = value;
        this.name = name;
    }

    public Integer getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    /**
     * 判断是否为已解锁状态
     * @param unlockState 解锁状态
     * @return 已解锁返回true，否则返回false
     */
    public static boolean isUnlocked(int unlockState) {
        return !isLocked(unlockState);
    }

    /**
     * 判断是否为未解锁状态
     * @param unlockState 解锁状态
     * @return 未解锁返回true，否则返回false
     */
    public static boolean isLocked(int unlockState) {
        if (WJS.value != unlockState && YJS.value != unlockState) {
            throw new GlobalException(ResponseCode.BAD_REQUEST, "非法的状态值：" + unlockState);
        }

        return YJS.value.equals(unlockState);
    }

}